package com.uchedao.seller.ui.car.publish.vin.http;

public class HttpFailureException extends Exception {

	private static String[] NETWORK_BASIC_ERROR_MESSAGE = new String[] { "无网络", "", "请求超时", "找不到目标服务器", "网络异常", "网络异常", "网络异常" };
	/**
	 * 
	 */
	private static final long serialVersionUID = -3512745323073393805L;

	/**
	 * -1:无网络 1:请求超时 2:找不到目标服务器 3:网络异常 4:网络异常 5:网络异常 >300:HttpResponseError
	 */
	private int mStatusCode;

	public HttpFailureException() {

	}

	/**
	 * 
	 * @param statusCode
	 *            -2:请求取消 -1:无网络 1:请求超时 2:找不到目标服务器 3:网络异常 4:网络异常 5:网络异常
	 *            >300:HttpResponseError
	 */
	public HttpFailureException(int statusCode) {
		mStatusCode = statusCode;
	}

	public HttpFailureException(Throwable error) {
		super(error);
	}

	/**
	 * 
	 * @param statusCode
	 *            -1:无网络 1:请求超时 2:找不到目标服务器 3:网络异常 4:网络异常 5:网络异常
	 *            >300:HttpResponseError
	 */
	public HttpFailureException(int statusCode, String message) {
		super(message);
		mStatusCode = statusCode;
	}

	/**
	 * 
	 * @return -1:无网络 1:请求超时 2:找不到目标服务器 3:网络异常 4:网络异常 5:网络异常
	 *         >300:HttpResponseError
	 */
	public int getStatusCode() {
		return mStatusCode;
	}

	public boolean isNetworkBasicError() {
		return mStatusCode >= -1 && mStatusCode <= 5;
	}

	@Override
	public String getMessage() {
		if (isNetworkBasicError()) {
			return NETWORK_BASIC_ERROR_MESSAGE[mStatusCode + 1];
		}
		if (super.getCause() != null) {
			return super.getCause().getMessage();
		}
		return super.getMessage();
	}

}
